new Vue({
    el:'#main',
    data:()=>({
        langs:[],
        lang:'zh',
        listData:[],
        pageSize:10,//分页条数
        page:1,//分页
        auth_ids:$('#adminauth_ids').text()
    }),
    async created(){
        await this.getLangs()
        await this.getData()
        $('.loding').hide()
        $("#delivery_type_Modal").on("hidden.bs.modal", ()=>{
            if(localStorage.getItem("model"))
            this.getData()
            localStorage.removeItem("model");
        });
    },
    methods:{
        //获取数据
        getData(){
            $('.loding').show()
            $.ajax({
                url:'/admin/saledeliverytype/list?request=requestAjax&lang='+this.lang+'&page='+this.page+'&limit='+this.pageSize,
                type:'post',
                success:data=>{
                    data = JSON.parse(data)
                    this.listData=data.data.data
                    this.page = data.data.page
                    this.Resetnav(this.page-0,data.data.pageSum)
                    $('.loding').hide()
                }
            })
        },
        //获取语言
        getLangs(){
            return new Promise((res,rej)=>{
                $.ajax({
                    url:'/admin/api/getLangType',
                    type:'post',
                    success:data=>{
                        this.langs = JSON.parse(data)     
                        res()   
                    }
                })
            })
        },
        //改变语言
        changelang(lang){
            this.lang=lang
            this.page=1
            this.getData()
        },
        //分页
        Resetnav(pageCurrent, pageSum) {
            //数据总条数
            var myPageCount = pageSum;
            //一页显示多少条
            var myPageSize = this.pageSize;
            //总页数
            var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
            $.jqPaginator('#pagination', {
                totalPages: parseInt(countindex),
                //最多显示多少页
                visiblePages: 5,
                //默认显示第几页
                currentPage: pageCurrent,
                first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                all:'<li class="page"><a href="javascript:;">'+myPageCount+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                onPageChange:(num, type)=>{
                    if (type == "change") {
                        this.page=num
                        this.getData()
                    }
                }
            });
        },
        deleteData(id){
            $.ajax({
                url:'/admin/saledeliverytype/deleteData?id='+id,
                type:'post',
                success:data=>{
                    data = JSON.parse(data)
                    change_mes_type('.payment .alert',data.status)
                    $('.alert').show()
                    $('.alert p').html('*'+data.msg)
                    if(data.status){
                        this.getData()
                    }
                }
            })
        }
    }
})
$("#delivery_type_Modal").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(".modal-content").children().remove();
});